package com.xiaoa.gossip.cluster.init;

import com.xiaoa.gossip.cluster.command.CurrentNodeState;
import com.xiaoa.gossip.cluster.config.ClusterConfig;
import com.xiaoa.gossip.cluster.service.ClusterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @author luokaichuang
 * @time 2020/5/7
 */
@Component
public class StartAfterProject  implements ApplicationRunner {

    //  配置
    @Autowired
    private ClusterConfig config;

    @Autowired
    private CurrentNodeState currentNodeState;

    @Autowired
    private ClusterService clusterService;

    @Override
    public void run(ApplicationArguments args) throws Exception {

        if (!StringUtils.isEmpty(config.getAddNodeIp())){

            // 加入其他机器
            clusterService.addToCluster(config.getAddNodeIp() , config.getAddNodePort());

        }

    }
}
